package com.qianchang.microfinance.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class APKUtils {
    /**
     * 获取当前本地apk的版本
     *
     * @param mContext
     * @return
     */
    public static int getVersionCode(Context mContext) {
        PackageManager manager = mContext.getPackageManager();
        int versionCode = 0;
        try {
            //获取软件版本号，对应AndroidManifest.xml下android:versionCode
            PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0);
            versionCode = info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    /**
     * 获取版本号名称
     *
     * @param mContext 上下文
     * @return
     */
    public static String getVerName(Context mContext) {
        PackageManager manager = mContext.getPackageManager();
        String verName = "";
        try {
            //获取软件版本号，对应AndroidManifest.xml下android:versionCode
            PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0);
            verName = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return verName;
    }
}
